//!@author denglibin
//!@date 2025/9/4 16:44
//!@desc

use std::env;
use crate::apps::AiParagraphVec;
use crate::dao::mysql2sqlite;
use crate::sys::global::GlobalResult;

pub async fn start() -> GlobalResult<()> {
    let mut mysql_url = "mysql://denglibin:denglibin@192.168.6.231:3307/yiscn_file_sys";
    let args = env::args().collect::<Vec<String>>();
    if args.len() > 1 {
        let p = args.get(1).unwrap();
        mysql_url = p;
    }
    
    let sqlite_url = "sqlite:ai_paragraph_vec.db";
    let columns = vec!["id", 
                         "deleted",
                         "create_time",
                         "update_time",
                         "create_by",
                         "update_by",
                         "update_by",
                         "table_id",
                         "es_id",
                         "file_id",
                         "file_md5",
                         "paragraph",
                         "vec",
                         "status",
                         "ai_id",
                         "text_paragraph_id",
                         "chinese",
                         "lang",
                      ].iter().map(|x| x.to_string()).collect::<Vec<String>>();
    let table_name = "ai_paragraph_vec";
    let create_table_sql =
        "create table if not exists ai_paragraph_vec(\
         id BIGINT primary_key,\
         deleted TINYINT,\
         create_time datetime,\
         update_time datetime,\
         create_by bigint,\
         update_by bigint,\
         table_id bigint,\
         es_id bigint,\
         file_id bigint,\
         file_md5 varchar(64),\
         paragraph TEXT,\
         vec TEXT,\
         status int,\
         ai_id bigint,\
         text_paragraph_id,\
         chinese text,\
         lang int\
         )";
    mysql2sqlite::mysql2sqlite::<AiParagraphVec>(
        mysql_url,
        sqlite_url,
        table_name,
        create_table_sql,
        columns,
        0,
    )
        .await
}